/**
 * Created by Administrator on 2017/3/7 0007.
 */
var Item={
    create:function (url,x,y,text,ans,sceneIdx) {
        var bool_down;
        var item={};
        var startOB={};
        console.log('item::::',url,resource[url]);

        // var t1=new PIXI.Sprite(resource['assets/images/page2_t1.png'].texture);

        item.ui=new PIXI.Sprite(resource[url].texture);
        item.ui.anchor.set(0.5);
        item.ui.x=x;
        item.ui.y=y;
        item.ui.on('pointerdown',downHandler);
        item.ui.on('pointermove',moveHandler);
        item.ui.on('pointerup',upHandler);
        item.ui.interactive=true;

        item.sceneIdx=sceneIdx;
        console.log('itemIDX::::::::::::::::',item.sceneIdx);

        var tw_shine=new TWEEN.Tween({scaleX:1,scaleY:1,alpha:1},Math.floor(300+Math.random()*200))
            .to({scaleX:1.02,scaleY:1.02,alpha:0.9})
            .onUpdate(function () {
                item.ui.alpha=this.alpha;
                item.ui.scale.x=this.scaleX;
                item.ui.scale.y=this.scaleY;
            })
            .delay(Math.floor(Math.random()*100))
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start();

        // function shine()
        // {
        //
        // }
        // item.In=function (delay) {
        //
        // }


        function downHandler(e) {
            e.data.originalEvent.stopImmediatePropagation();
            e.data.originalEvent.preventDefault();
            bool_down=true;
            startOB.x=e.data.global.x;
            startOB.y=e.data.global.y;
            // console.log('upHandler!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
            // var event = new CustomEvent("Game_ItemDown", {detail:text });
            // document.dispatchEvent(event);
        }
        function moveHandler(e) {
            e.data.originalEvent.stopImmediatePropagation();
            e.data.originalEvent.preventDefault();
            if(bool_down)
            {
                if((e.data.global.x-startOB.x)*(e.data.global.x-startOB.x)+(e.data.global.y-startOB.y)*(e.data.global.y-startOB.y)>100)
                {
                    bool_down=false;
                }
            }
        }
        function upHandler(e) {
            e.data.originalEvent.stopImmediatePropagation();
            e.data.originalEvent.preventDefault();
            if(bool_down)
            {
                bool_down=false;
                var event = new CustomEvent("Game_ItemDown", {detail:[text,ans,item.sceneIdx]});
                document.dispatchEvent(event);

            }

        }

        return item;
    }
}